﻿/* 
* FlexContainer Server Control for ASP.NET 2.0
* Copyright (C) 2009 Michael Paperin
* All rights reserved.
* 
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as 
* published by the Free Software Foundation.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*/

// Create root namespace
if (!window.RiaWebControls)
    RiaWebControls = Class.create();

RiaWebControls.FlexContainer = Class.create();

// Inherit from Gaia Control
Object.extend(RiaWebControls.FlexContainer.prototype, Gaia.Control.prototype);

// Implementation
Object.extend(RiaWebControls.FlexContainer.prototype, {

    // Constructor
    initialize: function(element, options) {
        this.initializeFlexContainer(element, options)
    },

    initializeFlexContainer: function(element, options) {
        // Calling base class constructor
        this.initializeControl(element, options);

        // initialize flash variables
        var flashVars = {
            name: this.options.name,
            src: this.options.flexSrc,
            width: this.options.width,
            height: this.options.height,
            menu: this.options.showFlashMenu,
            wmode: 'transparent'
        };

        // event hooks
        window.gaiaFlexCallHandler = function(controlId, str) { $G(controlId).onFlexCall(str); } .bind(this);
        this.onFlexCall = function(str) { this._dispatchIncomingJsonObject(str); } .bind(this);
        this.player = flashembed(this.element.id + '_object', flashVars, this.options.cfg);
    },

    FlexCallObject: function(args) {
        this.player.FlexCallObject(args);
        return this;
    },

    _dispatchIncomingJsonObject: function(str) {
        Gaia.Control.callControlMethod.bind(this)(
            "ContainerCallObject",
            [str],
            null,
            this.element.id);
    },

    // Destructor
    destroy: function() {
        this._destroyImpl();
    }
});

RiaWebControls.FlexContainer.browserFinishedLoading = true;